<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="出库编号" prop="wareoutNo">
        <el-input v-model="queryParams.wareoutNo" placeholder="请输入出库编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="cUsername">
        <el-input v-model="queryParams.cUsername" placeholder="请输入客户名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="审批状态" prop="approvalStatus" style="width: 220px">
        <el-select v-model="queryParams.approvalStatus" placeholder="请选择审批状态" clearable>
          <el-option v-for="dict in approval_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="完成状态" prop="status" style="width: 220px">
        <el-select v-model="queryParams.status" placeholder="请选择完成状态" clearable>
          <el-option v-for="dict in wareout_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warehouseoutList" >
      <el-table-column label="出库编号" align="center" prop="wareoutNo" />
      <el-table-column label="客户名称" align="center" prop="cUsername" />
      <el-table-column label="完成状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="wareout_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="ZoomIn" @click="openOrder(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

      
  <!-- 显示出库详情 -->
  <el-dialog title="出库订单信息" v-model="openOder" width="500px" append-to-body>
    <div class="demo-collapse">
      <el-collapse v-for="(form, index) in formdate" :key="form.wareoutOrederNo" accordion>
        <el-collapse-item :title="`订单号:${form.wareoutOrederNo}`">
          <div>
            <p>仓库: {{ form.warehouseName }}</p>
            <p>发货状态：{{ form.status === 0 ? '未发货' : '已发货' }}</p>
            <p v-if="form.trackingName && !form.showTrackingDialog">物流公司: {{ form.trackingName }}</p>
            <p v-if="form.trackingNo && !form.showTrackingDialog">物流单号: {{ form.trackingNo }}</p>
          </div>
          <el-table :data="form.goods" style="width: 100%">
            <el-table-column prop="name" label="商品名称" width="270" />
            <el-table-column prop="outboundNumber" label="数量" width="180" />
          </el-table>
        </el-collapse-item>
      </el-collapse>
    </div>
  </el-dialog>
  </div>

</template>

<script setup name="Warehouseout">
import { listWarehouseout } from "@/api/warehouseout/warehouseout";
import { reactive, ref } from "vue";
import {listOrederVo} from "@/api/warehouseout/oreder.js";
import user from "@/store/modules/user.js";

const { proxy } = getCurrentInstance();
const { approval_status, wareout_status } = proxy.useDict('approval_status', 'wareout_status');

const warehouseoutList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const openOder = ref(false)
let formdate = ref()
let wareoutNo = ref()
let status = ref()
let approvalStatus = ref()

//显示出库订单信息
function openOrder(row) {
  wareoutNo.value = row.wareoutNo
  status.value= row.status
  approvalStatus.value = row.approvalStatus
  listOrederVo(row.wareoutNo).then(resp => {
    formdate.value = resp
    formdate.value.forEach(form => {
      form.showTrackingDialog = false;
    });
    openOder.value = true
  })

}

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    wareoutNo: null,
    cUsername: null,
    approvalStatus: null,
    status: null
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询出库列表 */
function getList() {
  loading.value = true;
  queryParams.value.status=1
  queryParams.value.cUsername=user().name
  listWarehouseout(queryParams.value).then(response => {
    warehouseoutList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 表单重置
function reset() {
  form.value = {
    Id: null,
    wareoutNo: null,
    cUsername: null,
    approvalStatus: null,
    status: null
  };
  proxy.resetForm("warehouseoutRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
